<?php

/*
Process Add Enemy (admin_edit_enemy.pro.php)
*/

$rank_check = "7";
include "../global.inc.php";

$explodeAttacks = explode(", ", $attack_pattern);
$countAttacks = count($explodeAttacks) - 1;

for ($a = 0; $a <= $countAttacks;)
{
	$findItem = fetch("SELECT * FROM attacks2 WHERE attack_name = '$explodeAttacks[$a]' AND game = '$game'");
	if (!$findItem[id])
	{
		die(header(error("admin_edit_enemy.php?game=$game","The attack \"$explodeAttacks[$a]\" does not exsist!")));
	}
	$a++;
}

if ($HTTP_POST_FILES['petImage']['size'] >= 1)
{
	$directoryName = "$rootPath/images/user_images/opg_$game";
	if (!file_exists($directoryName)) { mkdir($directoryName, 0777); }
	
	$directoryName2 = 	"$rootPath/images/user_images/opg_$game/enemies";
	if (!file_exists($directoryName2)) { mkdir($directoryName2, 0777); }
	
	if ($HTTP_POST_FILES['petImage']['size'] >= 32000)
	{
		die(header(error("admin_edit_enemy.php?game=$game", "Your image must be under 32,000 bytes (or 	32kb)")));
	}
	
	if (!eregi("image/", $HTTP_POST_FILES['petImage']['type']))
	{
		die(header(error("admin_edit_enemy.php?game=$game", "You can only use .gif, .jpg, and .jpeg files 	for images. Please convert the image to one of these file types.")));
	}
}

$check = fetch("SELECT id FROM one_players2 WHERE id = '$edit' AND game = '$game'");

if (!$check[id])
{
	die(header(error("admin_edit_enemy.php?game=$game", "That pet doesn't exsist.")));
}
else
{

	mysql_query("UPDATE one_players2 SET name = '$add_pet_name' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET level = '$add_level' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET guys_left = '$to_kill' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET strength = '$add_strength' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET defense = '$add_defense' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET speed = '$add_speed' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET health = '$add_health' WHERE id = '$check[id]' AND game = '$game'");
	mysql_query("UPDATE one_players2 SET attack_pattern = '$attack_pattern' WHERE id = '$check[id]' AND game = '$game'");

	if ($HTTP_POST_FILES['petImage']['size'] >= 1)
	{
		$file = $HTTP_POST_FILES['petImage']['tmp_name'];
		$dest = "$rootPath/images/user_images/opg_$game/enemies/enemy_$check[id].gif";
		if (file_exists($dest)) { unlink($dest); }		
		copy($file, "$dest");
	}
	
	header("Location: admin_edit_enemy.php?game=$game&error=The+pet+$add_pet_name+has+been+edited!");
}

?>
